/**
 * 
 */
package org.hackystat.ui.sensordatabrowser.client;

import com.google.gwt.user.client.ui.ChangeListener;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

/**
 * @author David J. Nickles
 *
 */
public class CalendarPanels implements ChangeListener {
  
  private CalendarWidget calendar;
  private DataPanels datapanels;
  private HTML calPanelFeedback;
  private Image calPanelImage;
  private Session session;

  /**
   * Constructs a new Calendar panel.
   * @param session parameters.
   */
  public CalendarPanels(Session session) {
    this.session = session;

    HorizontalPanel calColumns = new HorizontalPanel();
    this.calPanelImage = new Image(Images.CAL_IMAGE);
    this.calPanelImage.setStyleName(Styles.STATUSIMAGESTYLE);
    calColumns.add(this.calPanelImage);
    VerticalPanel timerCol2Rows = new VerticalPanel();
    Label calPanelTitle = new Label("Calendar Browser");
    timerCol2Rows.add(calPanelTitle);
    calPanelTitle.setStyleName(Styles.SMALLLABELSTYLE);
    this.calPanelFeedback = new HTML("Select a day to browse.");
    this.calPanelFeedback.setStyleName(Styles.EXAMPLELABELSTYLE);
    timerCol2Rows.add(this.calPanelFeedback);
    calColumns.add(timerCol2Rows);
    RootPanel.get("calendarStatusSlot").clear();
    RootPanel.get("calendarStatusSlot").add(calColumns);
    
    VerticalPanel calSettingsPanel = new VerticalPanel();
    calSettingsPanel.setStyleName(Styles.SETTINGSPANELPANESTYLE);
    calSettingsPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    this.calendar = new CalendarWidget(session);
    this.calendar.addChangeListener(this);
    calSettingsPanel.add(this.calendar);
    RootPanel.get("calendarSettingsSlot").clear();
    RootPanel.get("calendarSettingsSlot").add(calSettingsPanel);
    
    this.datapanels = new DataPanels(session);
    this.datapanels.update(this.calendar.getDate());
  }

  /**
   * This method loads the data for the date that was clicked on.
   * @param sender widget that was clicked
   */
  public void onChange(Widget sender) {
    this.datapanels.update(this.calendar.getDate());
  }
}
